package com.wen.tian.bean;

import com.wen.tian.enums.BaseErrorInfoInterface;
import com.wen.tian.enums.CommonEnum;

/**
 * @author tww
 * ClassName: ResultUtil.java、
 * createTime: 2020年11月04日 18:09:07
 **/
public class ResultUtil {


    /**
     * 成功
     *
     * @return
     */
    public static Result success() {
        return success("");
    }

    /**
     * 成功
     *
     * @param data
     * @return
     */
    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(CommonEnum.SUCCESS.getResultCode());
        result.setMsg(CommonEnum.SUCCESS.getResultMsg());
        result.setData(data);
        return result;
    }

    /**
     * 成功
     *
     * @return
     */
    public static Result success(Integer code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static Result success(Integer code, String msg, Object data) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    /**
     * 成功
     *
     * @return
     */
    public static Result success(String msg) {
        return success(200, msg);
    }


    /**
     * 失败
     */
    public static Result error(BaseErrorInfoInterface errorInfo) {
        Result result = new Result();
        result.setCode(errorInfo.getResultCode());
        result.setMsg(errorInfo.getResultMsg());
        result.setData("");
        return result;
    }

    /**
     * 失败
     */
    public static Result error(Integer code, String message) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(message);
        result.setData("");
        return result;
    }

    /**
     * 失败
     */
    public static Result error(String message) {
        Result result = new Result();
        result.setCode(-1);
        result.setMsg(message);
        result.setData("");
        return result;
    }

}
